<?php

class FrontController{
	static function main(){
		require 'Libs/Config.php'; //de configuracion
		require 'Libs/SPDO.php'; //PDO con singleton
		require 'Libs/ControllerBase.php'; //Clase controlador base
		require 'Libs/ModelBase.php'; //Clase modelo base
		require 'Libs/View.php'; //Mini motor de plantillas
		require 'Libs/Session.php'; //Clase session
		require 'config.php'; //Archivo con configuraciones.
		
		if(!empty($_GET['controller']))
			$controlName = $_GET['controller'] . 'Controller';
		else
			$controlName = 'playerController';
			
		if(!empty($_GET['accion']))
			$accionName = $_GET['accion'];
		else
			$accionName = 'principal';

		
		$controllerPath = $config->get('controllersFolder') . $controlName . '.php';
		
		if (is_file($controllerPath))
			require($controllerPath);
		else
			header("Location: errores/404.php");

		if (is_callable(array($controlName, $accionName)) == false)
		{
			trigger_error ($controlName . '->' . $actionName . '` no existe', E_USER_NOTICE);
			return false;	
		}
				
		$controlador = new $controlName();
		
		$controlador->$accionName();
		
		
	}
		
}


?>
